﻿<script type="text/javascript">
    //树
    var zNodes_Permission_PermissionItem_SelectTree = [];
    var clickState_Permission_PermissionItem_SelectTree = false; //记录节点是否已选择
    var zTree1_Permission_PermissionItem_SelectTree;
    var setting_Permission_PermissionItem_SelectTree;

    setting_Permission_PermissionItem_SelectTree = {
        checkable: false,
        async: true,
        isSimpleData: true,
        asyncUrl: "/Permission/PermissionItem/GetPermissionItems",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "FullName",
        open: false,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_Permission_PermissionItem_SelectTree,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_Permission_PermissionItem_SelectTree
        }
    };

    function zTreeOnAsyncSuccess_Permission_PermissionItem_SelectTree(event, treeId, treeNode, msg) {
        //异步成功
    }

    //树的单击事件
    function zTreeOnClick_Permission_PermissionItem_SelectTree(event, treeId, treeNode) {
        //alert(treeNode.Id);
        $("#moduleID_Permission_PermissionItem_SelectTree").val(treeNode.Id);
        $("#moduleFullname_Permission_PermissionItem_SelectTree").val(treeNode.FullName);
        clickState_Permission_PermissionItem_SelectTree = true;
    }

    $(document).ready(function () {
        refreshTree_Permission_PermissionItem_SelectTree("/Permission/PermissionItem/GetPermissionItems");

    });
    function refreshTree_Permission_PermissionItem_SelectTree(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_Permission_PermissionItem_SelectTree.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree1_Permission_PermissionItem_SelectTree = $("#tree_Permission_PermissionItem_SelectTree").zTree(setting_Permission_PermissionItem_SelectTree, zNodes_Permission_PermissionItem_SelectTree);
    }
    $("#btnSave_Permission_PermissionItem_SelectTree").click(function () {
        if (!clickState_Permission_PermissionItem_SelectTree) {//如果没有选择节点就不能点击确定按钮
            alertMsg.error("请选择节点！");
            return false;
        }
        if ($("#moduleID_Permission_PermissionItem_SelectTree").val() != $("#Id").val()) {
            $("#txtParentName").val($("#moduleFullname_Permission_PermissionItem_SelectTree").val());
            $("#ParentId").val($("#moduleID_Permission_PermissionItem_SelectTree").val());
        } else
            alertMsg.error("父节点选择有误，请重新选择！");
        $.pdialog.closeCurrent();
    });
</script>
<div class="pageContentD">
    <div class="pageFormContent" layouth="60">
        <ul id="tree_Permission_PermissionItem_SelectTree" class="ztree">
        </ul>
    </div>
    <div class='formBar'>
        @Html.Hidden("moduleID_Permission_PermissionItem_SelectTree", "0")
        @Html.Hidden("moduleFullname_Permission_PermissionItem_SelectTree", "")
        <ul>
            <li>
                <button type="button" class="btn btn-success btn-sm" id="btnSave_Permission_PermissionItem_SelectTree">
                    保存</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm" id="btnCancel_Permission_PermissionItem_SelectTree">
                    取消</button>
            </li>
        </ul>
    </div>
</div>
